<template>
  <div>
<van-picker
  title="修改性别"
  show-toolbar
  :columns="columns"
  :default-index="localGender"
  @confirm="onConfirm"
  @cancel="$emit('close')"
  @change="onChange"
/>
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
export default {
  name: 'UpdateGender',
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  components: {},
  data () {
    return {
      columns: ['男', '女'],
      localGender: this.value
    }
  },
  created () {

  },
  methods: {
    async onConfirm () {
      this.$toast.loading({
        message: '保存中',
        duration: 0,
        forbidClick: true
      })
      await updateUserProfile({
        gender: this.localGender
      })
      this.$toast.success({
        message: '更新成功'
      })
      this.$emit('input', this.localGender)
      this.$emit('close')
    },
    onChange (picker, value, index) {
    //   console.log(picker, value, index)
      this.localGender = index
    }
  }
}
</script>

<style lang="less" scoped>

</style>
